package uk.ac.ebi.bioinvindex.utils.mock;

import uk.ac.ebi.bioinvindex.dao.BIIDAOException;
import uk.ac.ebi.bioinvindex.model.impl.term.FreeTextTermImpl;
import uk.ac.ebi.bioinvindex.model.impl.term.OntologyTermImpl;


/**
 * User: Nataliya Sklyar (nsklyar@ebi.ac.uk)
 * Date: Sep 14, 2007
 */
public class TermBuilder<T extends FreeTextTermImpl> {

	private T term;

	public TermBuilder(Class<T> termClass) {
		if (termClass == null) {
			throw new IllegalArgumentException("termClass cannot be null!");
		}

		try {
			term = termClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
			throw new BIIDAOException("Cannot instantiate class " + termClass, e);
		}
	}

	public TermBuilder id(Long id) {
		term.setId(id);
		return this;
	}

	public TermBuilder acc(String acc) {
		term.setAcc(acc);
		return this;
	}

	public TermBuilder name(String name) {
		term.setValue(name);
		return this;
	}

	public TermBuilder ontologyTerm(OntologyTermImpl ontologyTerm) {
		term.addOntologyTerm(ontologyTerm);
		return this;
	}
}
